from PyPDF3 import PdfFileReader,PdfFileWriter
writer=PdfFileWriter()
reader=PdfFileReader('test.pdf')
for page in range(reader.getNumPages()):
    writer.addPage(reader.getPage(page))
password=input('password: ')
writer.encrypt(user_pwd=password,owner_pwd=None,use_128bit=True)
f=open('out.pdf','wb')
writer.write(f)
f.close()
